﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Diagnostics;

//Namespace reference
using System;
using System.Resources;

namespace InstallerBD
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        List<SQLScript> files = new List<SQLScript>();
        public MainWindow()
        {
            var auxList = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
            foreach (var name in auxList)
            {
                if (name.EndsWith(".sql"))
                    this.files.Add(new SQLScript(name));
            }
            InitializeComponent();
        }



       

        private void Run_Click(object sender, RoutedEventArgs e)
        {
            if (ServerTextBox.Text.Trim() == "")
                MessageBox.Show("Не указано имя сервера", "error", MessageBoxButton.OK, MessageBoxImage.Error);
            else
                InstalationProces.show(files, ServerTextBox.Text, LoginTextBox.Text, PwdTextBox.Text);
        }

        private void DirSel_Click_1(object sender, RoutedEventArgs e)
        {
            var dlg = new System.Windows.Forms.FolderBrowserDialog();
            var res = dlg.ShowDialog();

            if (res == System.Windows.Forms.DialogResult.Cancel)
                return;

            files.Clear();
            string path = dlg.SelectedPath;
            foreach (var fileName in Directory.GetFiles(path, "*.sql"))
                files.Add(new SQLScript(fileName));
        }

        private void TextBlock_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
        {
            var dlg = new ShowScriptContent(files);
            dlg.ShowDialog();
        }

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
            e.Handled = true;
        }
         
    }
}
